#include "const.h"

int s_wildcard(const char *pattern, const char *source) {
	while(1) {
		//wildcard
		if (*pattern=='*') {
			// skip pattern while it's equal to '*'
			while(*pattern=='*')
				pattern++;

			// accept the rest of the string if the pattern ends in "*"
			if (*pattern==0)
				return 1;

			// enumerate the source string
			while(*source != *pattern) {
				// did the source string terminate?
				if (*source==0)
					// not what was wanted
					return 0;

				// okay, increment the source string
				source++;
			}

			// continue the loop
			continue;
		}

		// is the source character not equal to the pattern character?
		if (*source != *pattern)
			break; //break to keep the compiler happy

		// they're equal, is it a null termination?
		if (*source==0)
			return 1;

		// okay, there's more to the string, increment each
		source++;
		pattern++;
	}

	// not equal, return zero
	return 0;
}
